home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: July 1, 1997
- // Author: rh
- //
- // Description:
- // Helper dialog to launch the arrayMapper command.
- //
- // Contents:
- // makeMonochromRampAMW Make monochromatic ramp.
- // okayAMW() Callback for the OK button.
- // makeAttrName() Create a new attribute name.
- // replaceBtns() Rebuild the buttons in the menu.
- // makeAryAttrList() Get all array attributes from shape.
- // create() Build the dialog.
- // register() Register the callbacks.
- // ArrayMapperWnd() Main entry point. Launch dialog.
-
-
- global string $gArrayMapperObject = "";
- global string $gArrayMapperAttr = "";
-
-
-
- // ========== makeMonochromRampAMW ==========
- //
- // Description:
- // Make the ramp monochromatic if it is connected
- // to a doubleArray attribute (vs vectorArray).
- //
-
- global proc makeMonochromRampAMW( string $node, string $attr )
- {
-
- // Check if the attribute is of type doubleArray.
- //
- string $dblAttrAry[] = `particle -q -ppd $node`;
- int $dblAttrCnt = size( $dblAttrAry );
- int $isDoubleArray = 0;
-
- for ($i = 0; $i < $dblAttrCnt; $i++)
- {
- if ($attr == $dblAttrAry[$i])
- {
- $isDoubleArray = 1;
- break;
- }
- }
-
-
- // If attribute is double array, then make the
- // ramp monochromatic.
- //
- if ($isDoubleArray)
- {
- // Need to find the ramp node.
- //
- string $cnctAry[];
- string $arrayMapperNode;
- string $rampNode;
-
- $cnctAry = `listConnections -s true -d false ($node+"."+$attr)`;
- $arrayMapperNode = $cnctAry[0];
- $cnctAry = `listConnections -s true -d false ($arrayMapperNode+".computeNode")`;
- $rampNode = $cnctAry[0];
-
-
- // Set the ramp colors and positions to a monochromatic ramp.
- //
- setAttr ($rampNode+".colorEntryList[0].color") -type double3 1 1 1 ;
- setAttr ($rampNode+".colorEntryList[1].color") -type double3 0.5 0.5 0.5 ;
- setAttr ($rampNode+".colorEntryList[2].color") -type double3 0 0 0 ;
- setAttr ($rampNode+".colorEntryList[1].position") 0.5;
- setAttr ($rampNode+".colorEntryList[2].position") 1.0;
- }
-
-
- } // makeMonochromRampAMW //
-
-
-
- // ========== okayAMW ==========
- //
- // Description:
- // Callback for the OK button. This builds the actual
- // arrayMapper command string, and executes it.
- //
-
- global proc okayAMW( string $win, string $rowLyt )
- {
- setParent $win;
-
- // Start building the command string.
- //
- global string $gArrayMapperObject;
- global string $gArrayMapperAttr;
- string $cmd, $inU, $inV;
-
- $cmd = "arrayMapper -target "+$gArrayMapperObject+" -destAttr "+$gArrayMapperAttr;
-
-
- // Determine inputU flag.
- //
- int $uIndex = `optionMenu -q -select uSourceOM`;
-
- switch ($uIndex)
- {
- case 1 :
- // do nothing
- break;
-
- case 2 :
- $cmd += " -inputU ageNormalized";
- break;
-
- default:
- $cmd += " -inputU "+`optionMenu -q -value uSourceOM`;
- break;
- }
-
-
- // Determine inputV flag.
- //
- int $vIndex = `optionMenu -q -select vSourceOM`;
-
- switch ($vIndex)
- {
- case 1 :
- // do nothing
- break;
-
- case 2 :
- $cmd += " -inputV ageNormalized";
- break;
-
- default:
- $cmd += " -inputV "+`optionMenu -q -value vSourceOM`;
- break;
- }
-
-
- // Determine -type flag.
- //
- int $computeNode = `optionMenu -q -select mapOM`;
-
- switch ($computeNode)
- {
- case 1 :
- // do nothing
- break;
-
- case 2 :
- $cmd += " -type ramp";
- break;
-
- default :
- // Any button after the first two, contains the name of
- // a ramp node to use.
- //
- string $nodeName = `optionMenu -q -v mapOM`;
- $cmd += " -mapTo "+$nodeName;
- break;
- }
-
-
- // Execute the arrayMapper command.
- //
- evalEcho( $cmd );
- window -e -vis 0 $win;
-
-
- // Special case for monochromatic rmap. If the destination
- // attribute is a doubleArray, then fix the ramp to be
- // monochormatic.
- //
- if ($computeNode == 2)
- {
- makeMonochromRampAMW( $gArrayMapperObject, $gArrayMapperAttr );
- }
-
-
- // If the row layout was specifed, then update it.
- //
- if (size( $rowLyt ))
- {
- AEgenericUpdateOneTextfield( $gArrayMapperObject, $gArrayMapperAttr, $rowLyt );
- }
-
-
- } // okayAMW //
-
-
-
- // ========== makeAttrName ==========
- //
- // Description:
- // Given an attribute name, insert the given character
- // before the 'PP' characters if they are present.
- //
-
- proc string makeAttrName( string $char, string $name )
- {
- string $s1 = $char+"PP";
- string $s2 = substitute( "PP", $name, $s1 );
-
- if ($s2 == $name)
- {
- $s2 = $name+$char;
- }
-
- return( $s2 );
-
-
- } // makeAttrName //
-
-
-
- // ========== replaceBtns ==========
- //
- // Description:
- // Replace the buttons in the menu with
- // the new buttons.
- //
-
- proc replaceBtns( string $win, string $menu, string $newBtnAry[] )
- {
-
- setParent $win;
-
-
- // Delete the old buttons.
- //
- string $oldBtnAry[] = `optionMenu -q -ils $menu`;
- int $oldBtnCnt = size( $oldBtnAry );
-
- for ($i = 0; $i < $oldBtnCnt; $i++)
- {
- deleteUI $oldBtnAry[$i];
- }
-
-
- // Add the new buttons.
- //
- int $newBtnCnt = size( $newBtnAry );
-
- for ($i = 0; $i < $newBtnCnt; $i++)
- {
- menuItem -p $menu -l $newBtnAry[$i];
- }
-
-
- } // replaceBtns //
-
-
-
- // ========== makeAryAttrList ==========
- //
- // Description:
- // Make a list of all array attributes available
- // in the particle shape which are suitable for
- // using as input attributes to the mapper node.
- // Make sure to remove the given attribute because
- // it is already being used as the output node.
- // Also, remove the ageNormalized attribute because
- // it is redundant with the "Particle's Age" item.
- //
-
- proc string[] makeAryAttrList( string $win, string $node, string $outAttr )
- {
- string $attrList[] = `particle -q -ppd $node`;
- int $attrCnt = size( $attrList );
- string $aryList[];
- int $len;
- int $outCnt = 0;
-
-
- for ($i = 0; $i < $attrCnt; $i++)
- {
- if (($attrList[$i] != $outAttr) && ($attrList[$i] != "ageNormalized"))
- {
- $aryList[$outCnt++] = $attrList[$i];
- }
- }
-
-
- return( $aryList );
-
-
- } // makeAryAttrList //
-
-
-
- // ========== create ==========
- //
- // SYNOPSIS
- // Create the window and all the controls.
- //
-
- proc create( string $win )
- {
-
- // Create window and base container widgets.
- //
- window
- -title "Create Ramp Options"
- -widthHeight 400 400
- -minimizeButton false
- -maximizeButton false
- -retain
- -sizeable true
- -resizeToFitChildren false
- $win;
-
- formLayout -nd 100 workLyt;
-
- text -l "none" headerTxt;
- formLayout -e
- -af headerTxt left 4
- -af headerTxt top 4
- workLyt;
-
- optionMenu -l "Input U" uSourceOM;
- menuItem -l "<None>";
- formLayout -e
- -af uSourceOM left 12
- -ac uSourceOM top 4 headerTxt
- workLyt;
-
- optionMenu -l "Input V" vSourceOM;
- menuItem -l "<None>";
- formLayout -e
- -af vSourceOM left 12
- -ac vSourceOM top 4 uSourceOM
- workLyt;
-
- optionMenu -l "Map To" mapOM;
- menuItem -l "<None>";
- formLayout -e
- -af mapOM left 10
- -ac mapOM top 4 vSourceOM
- workLyt;
-
- button -l "OK" -w 100 -h 26 okBtn;
- formLayout -e
- -ap okBtn left -50 25
- -af okBtn bottom 4
- workLyt;
-
- button -l "Cancel" -w 100 -h 26 cancelBtn;
- formLayout -e
- -ap cancelBtn left -50 75
- -af cancelBtn bottom 4
- workLyt;
-
- separator -horizontal true sep1;
- formLayout -e
- -af sep1 left 0
- -af sep1 right 0
- -ac sep1 bottom 4 okBtn
- workLyt;
-
-
- } // create //
-
-
-
- // ========== register ==========
- //
- // Description:
- // Register the callbacks on the widgets.
- //
-
- proc register( string $win )
- {
-
- setParent $win;
-
- button -e -c ("window -e -vis 0 "+$win) cancelBtn;
-
-
- } // register //
-
-
-
- // ========== update ==========
- //
- // Description:
- // Build the option menus to reflect the current
- // state of the scene.
- //
-
- proc update( string $win, string $node, string $dstAttr, string $rowLyt )
- {
-
- setParent $win;
-
-
- // Put the attribute name in the header text.
- //
- text -e -l ("Destination Attribute: "+$dstAttr) headerTxt;
-
-
- // Get the available list of array attributes.
- //
- string $attrAry[] = makeAryAttrList( $win, $node, $dstAttr );
- int $attrCnt = size( $attrAry );
-
-
- // Set the first two buttons for the input option menus.
- //
- string $btnAry[];
- $btnAry[0] = "<None>";
- $btnAry[1] = "Particle's Age";
-
-
- // Source U menu.
- //
- $btnAry[2] = makeAttrName( "U", $dstAttr );
-
- for ($i = 0; $i < $attrCnt; $i++)
- {
- $btnAry[$i+3] = $attrAry[$i];
- }
-
- replaceBtns( $win, "uSourceOM", $btnAry );
-
-
- // Source V menu.
- //
- $btnAry[2] = makeAttrName( "V", $dstAttr );
- replaceBtns( $win, "vSourceOM", $btnAry );
- optionMenu -e -sl 2 vSourceOM;
-
-
- // Map menu.
- //
- string $mapBtns[];
- string $rampAry[] = `ls -type ramp`;
- int $rampCnt = size( $rampAry );
-
- $mapBtns[0] = "<None>";
- $mapBtns[1] = "New Ramp";
-
- for ($i = 0; $i < $rampCnt; $i++)
- {
- $mapBtns[$i+2] = $rampAry[$i];
- }
-
- replaceBtns( $win, "mapOM", $mapBtns );
- optionMenu -e -sl 2 mapOM;
-
-
- // Need to register a new callback each time because
- // the row layout changes. It gets passed in by
- // the textfield popup menu.
- //
- button -e -c ("okayAMW "+$win+" "+$rowLyt) okBtn;
-
-
- } // update //
-
-
-
- // ========== ArrayMapperWnd ==========
- //
- // Description:
- // Main entry point. Must be last procedure in file.
- //
-
- global proc ArrayMapperWnd( string $node, string $attr, string $rowLyt )
- {
- string $win = "ArrayMapperWnd";
-
- if (! `window -exists $win`)
- {
- create( $win );
- register( $win );
- }
-
- update( $win, $node, $attr, $rowLyt );
-
-
- // Save the node name and attribute in a global
- // variable, so the callback can get access to it.
- //
- global string $gArrayMapperObject;
- global string $gArrayMapperAttr;
-
- $gArrayMapperObject = $node;
- $gArrayMapperAttr = $attr;
-
- showWindow( $win );
-
-
- } // ArrayMapperWnd //
-